<template>
  <table-block>
    <template-query
      slot="query"
      :configs="queryListFields"
      inline-item
      @query="handleSearch"
    >
      <template #btn>
        <el-button type="primary" @click="goCreate()">新增</el-button>
      </template>
    </template-query>
    <template-table
      :datas="datas"
      is-order-number
      :loading="isLoading"
      :configs="templateClassTableFields"
      need-mark-prop="status"
      :need-mark-prop-val="-1"
      @refresh="fetchData"
    >
      <el-table-column fixed="right" label="操作" width="135">
        <template slot-scope="{ row }">
          <popconfirm
            class="mr-1"
            title="删除"
            text="确认删除???"
            @confirm="deleteTemplateClass(row)"
          />
          <el-button type="text" @click="goEdit(row)">编辑</el-button>
        </template>
      </el-table-column>
    </template-table>
    <el-pagination
      slot="pagination"
      :current-page="page"
      :page-size="limit"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @current-change="handlePageChange"
      @size-change="handleLimitChange"
    />
  </table-block>
</template>

<script>
var vk = uni.vk;  
import { getTemplateCalssList, deleteTemplateClass } from 'dependencies/api/templateClass'
import { templateClassTableFields, queryListFields, columns } from './config'
import TablePageMixins from 'modules/mixins/table-page'
export default {
  name: 'AvatarTemplate',
  mixins: [TablePageMixins],
  data() {
    return {
      templateClassTableFields,
      queryListFields,
      queryParam: {}
    }
  },
  mounted() {
    this.fetchData()
  },
  methods: {
    goEdit(row) {
      vk.navigateTo(`/pages/avatar-class/edit?_id=${row._id}`);
    },
    async deleteTemplateClass(row) {
      try {
        await deleteTemplateClass({
          _id: row._id
        })
        this.fetchData()
        this.$message.success('操作成功!')
      }catch(err){
        
      }
    },
    goCreate() {
      vk.navigateTo('/pages/avatar-class/edit');
    },
    getDatas() {
      return getTemplateCalssList({
        formData: this.queryParam,
        pageIndex: this.page,
        pageSize: this.limit,
        columns: columns
      })
    },
    handleSearch(params) {
      this.queryParam = { ...params }
      this.page = 1
      this.fetchData()
    }
  }
}
</script>
